package com.jiyun.play.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.domain.Orders;
import com.domain.Play;
import com.jiyun.play.mapper.PlayMapper;
import com.jiyun.play.service.OrdersService;
import com.jiyun.play.mapper.OrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
* @author lenovo
* @description 针对表【orders】的数据库操作Service实现
* @createDate 2024-12-20 17:04:39
*/
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders>
    implements OrdersService{
    @Autowired
    private OrdersMapper ordersMapper;
    @Override
    public Orders addOrders(Orders orders) {
        Random random = new Random();
        // 生成100000到999999之间的随机数
        int i = random.nextInt(900000);
        // 订单号为6位随机数
        orders.setOrderNumber(String.valueOf(i));
        //判断前端传来的
        orders.setUserId(orders.getUserId());
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();

        orders.setPlayTime(new Date());
        // 判断开始时间是否大于当前时间一个小时
        if (orders.getStartTime().isAfter(now.plus(1, ChronoUnit.HOURS))) {
            System.out.println("================开始时间大于当前时间一个小时");
            orders.setStatus(0);
        } else {
            orders.setStatus(1);
            System.out.println("================开始时间不大于当前时间一个小时");
        }

        orders.setPid(orders.getPid());

        ordersMapper.insert(orders);
        return orders;
    }

    @Override
    public List<Orders> findAll() {
        List<Orders> orders = ordersMapper.findAll();
        return orders;
    }
}




